#include "ReflectableOptional.h"
#include "Reflection/Type.h"

void CReflectableOptional::SetValueWithType(CType *InDataType, const void *InValue)
{
    if(Data)
    {
        InDataType->EraseInstance(Data);
        InDataType->CloneInstance(InValue, Data);
    }
    else
    {
        Data = InDataType->CloneInstance(InValue);
    }
}

void CReflectableOptional::EraseValueWithType(CType *InDataType)
{
    if(Data)
    {
        InDataType->EraseInstance(Data);
        Data = nullptr;
    }
}

void CReflectableOptional::CloneWithType(CType *InDataType, CReflectableOptional *OutMemory) const
{
    if(Data)
    {
        InDataType->CloneInstance(Data, OutMemory->Data);
    }
    else
    {
        OutMemory->Data = nullptr;
    }
}
